package com.wuyou.simple;

import com.sun.xml.internal.ws.util.StringUtils;

/**
 * 检查单词是否为句中其他单词的前缀
 */
public class IsPrefixOfWord {

    public static void main(String[] args) {

        String sentence = "hellohello hellohellohello";
        String searchWord = "ell";
        System.out.println(solution_1(sentence, searchWord));
    }

    public static int solution_1(String sentence, String searchWord) {
        String[] s = sentence.split(" ");
        int res = -1;
        for (int i = 0; i < s.length; i++) {
            if (s[i].length() >= searchWord.length()) {
                String temp = s[i].substring(0, searchWord.length());
                if (temp.equals(searchWord)) {
                    res = i + 1;
                    return res;
                }
//                s[i].startsWith();
            }
        }

        return res;

    }
}
